<%#
 Copyright 2020-2022 sirpdboy Wich <sirpdboy@qq.com>
 https://github.com/sirpdboy/netspeedtest
 Licensed to the public under the Apache License 2.0.
-%>

<script type="text/javascript" src="<%=resource%>/cbi.js?v=1.1"></script>
<%+cbi/valueheader%>
<script type="text/javascript">
	var stxhr = new XHR();
	function update_status(btn,field, proto)
	{
		var tool = field.name;
		var addr = field.value;
		var protocol = proto ;
		var legend = document.getElementById('test-iperf-legend');
		var output = document.getElementById('test-iperf-output');
		if (legend && output)
		{
			output.innerHTML =
				'<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
				'<%:Waiting for command to complete...%>';
			legend.parentNode.style.display = 'block';
			legend.style.display = 'inline';
			btn.value='<%:Waiting (executing)...%>';
			btn.disabled=true;
			stxhr.post('<%=url('admin/network')%>/test_' + tool + protocol + '/' + addr, { token: '<%=token%>' },
				function(x)
				{
					if (x.responseText)
					{
						legend.style.display = 'none';
						output.innerHTML = String.format('<pre>%h</pre>', x.responseText);
					}
					else
					{
						legend.style.display = 'none';
						output.innerHTML ='</p>  <%:Operation execution complete%></p>';
					}
				
						btn.disabled=false;
						btn.value='<%:Click to execute%>';
				}
			);
		}
}
</script>

<form method="post"  class="cbi-map" action="<%=url('admin/network/netspeedtest')%>">
			<div class="cbi-value" >
				<label class="cbi-value-title"  ><%:Select function%></label>
				<div class="cbi-value-field">
  			    	<input style="margin: 5px 0"  type="hidden" value="" name="iperf" />
                    <select name="iperf_to" style="width:auto">
                    <option value="0" selected="selected"><%:iperfstart%></option>
                    <option value="1"><%:iperfstop%></option>
                    </select> 
					<div class="cbi-value-description">
				             <%:The speed measurement terminal must be in the same LAN as the router that starts the speed measurement%><br />
				             <%:Operation steps: start router speed measurement service download test client run speed measurement client input IP address of router speed measurement service%>
			 </div></div></div>
			<div class="cbi-value" ><label class="cbi-value-title"  ><%:Execute selected functions%></label>
		    	<div class="cbi-value-field"><input type="button" value="<%:Click to execute%>" class="cbi-button cbi-button-apply" onclick="return update_status(this,this.form.iperf,this.form.iperf_to.selectedIndex)" />
		    </div></div>
			<div class="cbi-value" >
			   <label class="cbi-value-title"><%:Iperf3 speed measurement software download%></label>
		           <div class="cbi-value-field">
				         <input type="button" class="cbi-button cbi-input-reload" value="<%:Github download iperf3%>" onclick="javascript:window.open('https://github.com/sirpdboy/netspeedtest/releases','target');" />
                         <input type="button" class="cbi-button cbi-input-reload" value="<%:Download from foreign official websites%>" onclick="javascript:window.open('https://iperf.fr/iperf-download.php','target');" />
		          </div>
			</div>
			<div class="cbi-value" >
			   <label class="cbi-value-title"><%:iperf3 commands reference%></label>
		           <div class="cbi-value-field">
							<%:-c, --client host ................run in client mode, connecting to host%><br />
							<%:-s, --server .....................run in server mode%><br />
							<%:-u, --udp ........................use UDP rather than TCP%><br />
							<%:-b, --bandwidth ..<number>[KMG]...target bandwidth in bits/sec (0 for unlimited)%><br />
							<%:-t, --time .......<number>........time in seconds to transmit for (default 10 secs)%><br />
							<%:-i, --interval ...<number>........seconds between periodic bandwidth reports%><br />
							<%:-P, --parallel ...<number>........number of parallel client streams to run%><br />
							<%:-R, --reverse ....................run in reverse mode (server sends, client receives)%><br />
				  </div>
		    </div>
  <fieldset class="cbi-section" style="display:none">
    <legend id="test-iperf-legend">
    <%:Collecting data...%>
    </legend>
    <span id="test-iperf-output"></span>
  </fieldset>
</form>

<%+cbi/valuefooter%>
